package batch

import "time"

type CreateBatchWorkReq struct {
	Name     string      `json:"name"`
	Type     string      `json:"type"`
	List     []Detail    `json:"list"`
	Template interface{} `json:"template"`
}

type Batch struct {
	ID              string    `json:"id"`
	UserID          string    `json:"user_id"`
	Username        string    `json:"username"`
	Name            string    `json:"name"`
	Type            string    `json:"type"`
	SuccessCount    int       `json:"success_count"`
	FailureCount    int       `json:"failure_count"`
	PendingCount    int       `json:"pending_count"`
	Status          string    `json:"status"`
	CreateTimestamp time.Time `json:"create_timestamp"`
	StartTimestamp  time.Time `json:"start_timestamp"`
	EndTimestamp    time.Time `json:"end_timestamp"`
	Success         []Detail  `json:"success,omitempty"`
	Failure         []Detail  `json:"failure,omitempty"`
	Pending         []Detail  `json:"pending,omitempty"`
	Template        string    `json:"-"`
}

type Detail struct {
	Cluster    string    `json:"cluster"`
	Deployment string    `json:"deploy,omitempty"`
	Node       string    `json:"node,omitempty"`
	Namespace  string    `json:"namespace,omitempty"`
	Message    string    `json:"message,omitempty"`
	Timestamp  time.Time `json:"timestamp"`
}

type List struct {
	Count int64   `json:"count"`
	Item  []Batch `json:"item,omitempty"`
}

const (
	CreateType  = "create"
	UpgradeType = "upgrade"
)

var AllowBatchWorkType = []string{
	CreateType,
	UpgradeType,
}

var NamePattern = `[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*`

const (
	BatchWorkLabel string = "endedgecloud.zjlab.io/batch"
	AppLabel       string = "app"
	K8sAppLabel    string = "k8s-app"
	ClusterLabel   string = "endedgecloud.zjlab.io/cluster"
	DefaultLabel   string = "endedgecloud.zjlab.io/default"

	GroupIDKey     = "endedgecloud.zjlab.io/groupid"
	UserIDKey      = "endedgecloud.zjlab.io/useruuid"
	UserNameKey    = "endedgecloud.zjlab.io/username"
)
